package com.EM1.www.servlet;

import com.EM1.www.dao.ConnectPaper;
import com.EM1.www.po.Paper;
import com.EM1.www.po.Teacher;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/PaperMsg")
public class PaperMsg extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        HttpSession session = request.getSession();
        Teacher teacher = (Teacher) session.getAttribute("teacher");
        ConnectPaper connectPaper=new ConnectPaper();
        ArrayList<Paper> papers = null;
        try {
            papers = connectPaper.selectPapers(teacher.getId());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        System.out.println(papers);
        session.setAttribute("papers",papers);
        request.getRequestDispatcher("paper.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
